import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:thinking/config/_.dart';
import 'package:thinking/utils/_.dart';
import 'package:thinking/widget/_.dart';
import 'package:thinking/entity/_.dart';

class RecentVisit extends StatelessWidget{

  final List<UserData> recentVisitList;

  RecentVisit({required this.recentVisitList});



  @override
  Widget build(BuildContext context) {
      return Panel(
        top: 10,
        bottom: 10,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Expanded(flex: 1, child: Text('最近访问',style: TextStyle(fontSize: 17,fontWeight:FontWeight.w600 ),),),
                GestureDetector(
                  onTap: (){

                    Modular.to.pushNamed('/moreRecentVisit');

                  },
                  child: Row(
                    children: [
                      Text(
                        "查看更多",
                        style: TextStyle(color: ColorConfig.TextColor,fontSize: 12),
                      ),
                      Icon(
                        Icons.arrow_forward_ios,
                        size: 10,
                        color: ColorConfig.TextColor,
                      )
                    ],
                  ),
                ),

              ],
            ),
            Container(
              margin: EdgeInsets.only(top: 10),
              height: Screen.setHeight(77),
              child: GridView.builder(
                physics: BouncingScrollPhysics(),
                shrinkWrap: true,
                scrollDirection: Axis.horizontal,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 1,
                  childAspectRatio: 1.1
                ),
                itemCount: recentVisitList.length,
                itemBuilder: (context,index){
                  return GestureDetector(
                    onTap: (){
                      Modular.to.pushNamed('/personal/${recentVisitList[index].userId}');
                    },
                    child: Column(
                      children: [
                        Container(
                            child: ClipRRect(
                              child:  ClipOval(
                                child: CachedNetworkImage(
                                  imageUrl: recentVisitList[index].userHeadImg!,
                                  fit: BoxFit.cover,
                                  width: Screen.setWidth(50),
                                  height: Screen.setWidth(50),
                                  errorWidget: (context, url, error) =>
                                  new Icon(Icons.error),
                                  placeholder: (context, url) => Container(
                                    width: Screen.setWidth(50),
                                    height: Screen.setWidth(50),
                                    color: ColorConfig.ThemeObsColor,
                                  ),
                                ),
                              ),
                            ),
                            decoration:BoxDecoration(
                                borderRadius: BorderRadius.all(Radius.circular(25)),
                                border: Border.all(width: 1,color: ColorConfig.ThemeColor)
                            )
                        ),
                        Container(
                          margin: EdgeInsets.only(top: 5),
                          child: Text(
                            recentVisitList[index].userNickName!,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                                fontSize: 12
                            ),
                          ),
                        )
                      ],
                    ),
                  );
                },
              ),
            ),
          ],
        ),
      );
  }

}